import * as constant from './constant'
import axios from 'axios'
import { fromJS } from 'immutable';
const getWrap = (result) => ({
    type: constant.GET_WRAP_DATA,
    wrapData: result.wrapData
})
const addData = (result, nextPage) => ({
    type: constant.ADD_MORE_DATA,
    list: fromJS(result),
    nextPage

})
export const getData = () => {
  return (dispatch) => {
     axios.get('/api/wrap.json').then((res) => {
         const result = res.data.data;
         dispatch( getWrap(result) );
     })
  }
}
export const getMore = (page) => {
    return (dispatch) => {
        axios.get('/api/wrap2.json?page' + page).then((res) => {
            const result = res.data.data;
            dispatch( addData(result, page + 1) )
        })
    }
}